<?php

namespace app\tenant\controller;

use think\Controller;
use Util\SysDb;
use think\Db;

class Data extends Controller
{
    public function everdaylist()
    {
        $page = trim(input('param.pageNo'));
        $tenantId = trim(input('param.tenantId'));
        $limit = trim(input('param.pageSize'));
        $tol = (intval($page) - 1) * $limit;

        $list = DB::name("sys_summary")->order("create_time desc")->limit($tol, $limit)->where(['tenant_id ' => $tenantId])->select();

        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $list]));
    }
    public function everdayalllist()
    {
        // ->where(['store_id' => $storeId])->lists()
        $this->db = new SysDb();

        $count = $this->db->table('tenant_info')->lists();

        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $count]));
    }
    public function everdaycount()
    {
        $tenantId = trim(input('param.tenantId'));
        $this->db = new SysDb();

        $count = $this->db->table('sys_summary')->where(['tenant_id ' => $tenantId])->count();

        exit(json_encode(['code' => 1, 'message' => 'succ', "result" => $count]));
    }
    public function registercountData()
    {
        $tenantId = trim(input('param.tenantId'));
        $thisSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'd')->find();
        if ($thisSum['bus_num'] == 0) {
            $thisSum = 0;
        }
        // 获取本周的注册人数
        $sevenSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'w')->select();
        $week = 0;
        foreach ($sevenSum as  $k => &$value) {
            $week = $value['bus_num'] + $week;
        }
        $sevenSum = $week;
        // 获取本月的注册人数
        $thirtySum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'm')->select();
        $thirty = 0;
        foreach ($thirtySum as  $k => &$value) {
            $thirty = $value['bus_num'] + $thirty;
        }
        $thirtySum = $thirty;
        // 获取今年的注册人数
        $yearSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'y')->select();
        $year = 0;
        foreach ($yearSum as  $k => &$value) {
            $year = $value['bus_num'] + $year;
        }
        $yearSum = $year;
        $array = array();
        $array["thisSum"] = $thisSum;
        $array["sevenSum"] = $sevenSum;
        $array["thirtySum"] = $thirtySum;
        $array["yearSum"] = $yearSum;
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>  $array]));
    }
    public function registersummaryCount()
    {
        $dateType =trim(input('param.dateType'));
        $tenantId = trim(input('param.tenantId'));
        $startTime = trim(input('param.startTime'));
        $endTime = trim(input('param.endTime'));
        $year =  array();    
        if($dateType=="year"){
        $num = explode('-', $startTime);
        $times=$num[0];
        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-01-01", $times."-02-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[0]['COUNT']=$count1; 
        $year[0]['dateTime']="1";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-02-01", $times."-03-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[1]['COUNT']=$count1; 
        $year[1]['dateTime']="2";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-03-01", $times."-04-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[2]['COUNT']=$count1; 
        $year[2]['dateTime']="3";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-04-01", $times."-05-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[3]['COUNT']=$count1; 
        $year[3]['dateTime']="4";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-05-01", $times."-06-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[4]['COUNT']=$count1; 
        $year[4]['dateTime']="5";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-06-01", $times."-07-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[5]['COUNT']=$count1; 
        $year[5]['dateTime']="6";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-07-01", $times."-08-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[6]['COUNT']=$count1; 
        $year[6]['dateTime']="7";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-08-01", $times."-09-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[7]['COUNT']=$count1; 
        $year[7]['dateTime']="8";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-09-01", $times."-10-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[8]['COUNT']=$count1; 
        $year[8]['dateTime']="9";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-10-01", $times."-11-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[9]['COUNT']=$count1; 
        $year[9]['dateTime']="10";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-11-01", $times."-12-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[10]['COUNT']=$count1; 
        $year[10]['dateTime']="11";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-12-01", $times."-12-31"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['bus_num'] + $one;
        }
        $count1 = $one;
        $year[11]['COUNT']=$count1; 
        $year[11]['dateTime']="12";
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
        }
        
        if($dateType=="month"||$dateType=="week"){
            $num = explode('-', $startTime);
            $years=$num[0];
            $mount=$num[1];
            for($i=1;$i<32;$i++){
                ${'count'.$i} = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereBetweenTime('create_time', $years."-".$mount."-".$i)->limit(1)->order("create_time desc")->find();
                if(${'count'.$i}==""){
                    ${'num'.$i}['COUNT']=0;
                }else{
                    ${'num'.$i}['COUNT']= ${'count'.$i}['bus_num'];
                }
                ${'num'.$i}['dateTime']= $i;
            array_push($year,  ${'num'.$i});
            // array_push($year,  ${'count'.$i});
            }
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
            }
      
    }

    public function rechargecountData()
    {
        $tenantId = trim(input('param.tenantId'));
        $thisSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'd')->find();
        if ($thisSum['recharge'] == 0) {
            $thisSum = 0;
        }
        // 获取本周的注册人数
        $sevenSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'w')->select();
        $week = 0;
        foreach ($sevenSum as  $k => &$value) {
            $week = $value['recharge'] + $week;
        }
        $sevenSum = $week;
        // 获取本月的注册人数
        $thirtySum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'm')->select();
        $thirty = 0;
        foreach ($thirtySum as  $k => &$value) {
            $thirty = $value['recharge'] + $thirty;
        }
        $thirtySum = $thirty;
        // 获取今年的注册人数
        $yearSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'today')->select();
        $year = 0;
        foreach ($yearSum as  $k => &$value) {
            $year = $value['recharge'] + $year;
        }
        $lastSum = $year;
        $array = array();
        $array["thisSum"] = $thisSum;
        $array["sevenSum"] = $sevenSum;
        $array["thirtySum"] = $thirtySum;
        $array["lastSum"] = $lastSum;
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>  $array]));
    }
    public function rechargesummaryCount()
    {
        $dateType =trim(input('param.dateType'));
        $tenantId = trim(input('param.tenantId'));
        $startTime = trim(input('param.startTime'));
        $endTime = trim(input('param.endTime'));
        $year =  array();    
        if($dateType=="year"){
        $num = explode('-', $startTime);
        $times=$num[0];
        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-01-01", $times."-02-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[0]['sum']=$count1; 
        $year[0]['dateTime']="1";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-02-01", $times."-03-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[1]['sum']=$count1; 
        $year[1]['dateTime']="2";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-03-01", $times."-04-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[2]['sum']=$count1; 
        $year[2]['dateTime']="3";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-04-01", $times."-05-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[3]['sum']=$count1; 
        $year[3]['dateTime']="4";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-05-01", $times."-06-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[4]['sum']=$count1; 
        $year[4]['dateTime']="5";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-06-01", $times."-07-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[5]['sum']=$count1; 
        $year[5]['dateTime']="6";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-07-01", $times."-08-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[6]['sum']=$count1; 
        $year[6]['dateTime']="7";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-08-01", $times."-09-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[7]['sum']=$count1; 
        $year[7]['dateTime']="8";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-09-01", $times."-10-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[8]['sum']=$count1; 
        $year[8]['dateTime']="9";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-10-01", $times."-11-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[9]['sum']=$count1; 
        $year[9]['dateTime']="10";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-11-01", $times."-12-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[10]['sum']=$count1; 
        $year[10]['dateTime']="11";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-12-01", $times."-12-31"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['recharge'] + $one;
        }
        $count1 = $one;
        $year[11]['sum']=$count1; 
        $year[11]['dateTime']="12";
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
        }
        
        if($dateType=="month"||$dateType=="week"){
            $num = explode('-', $startTime);
            $years=$num[0];
            $mount=$num[1];
            for($i=1;$i<32;$i++){
                ${'count'.$i} = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereBetweenTime('create_time', $years."-".$mount."-".$i)->limit(1)->order("create_time desc")->find();
                if(${'count'.$i}==""){
                    ${'num'.$i}['sum']=0;
                }else{
                    ${'num'.$i}['sum']= ${'count'.$i}['recharge'];
                }
                ${'num'.$i}['dateTime']= $i;
            array_push($year,  ${'num'.$i});
            // array_push($year,  ${'count'.$i});
            }
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
            }
      
    }

     public function packagecountData()
    {
        $tenantId = trim(input('param.tenantId'));
        $thisSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'd')->find();
        if ($thisSum['pk_num'] == 0) {
            $thisSum = 0;
        }
        // 获取本周的注册人数
        $sevenSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'w')->select();
        $week = 0;
        foreach ($sevenSum as  $k => &$value) {
            $week = $value['pk_num'] + $week;
        }
        $sevenSum = $week;
        // 获取本月的注册人数
        $thirtySum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'm')->select();
        $thirty = 0;
        foreach ($thirtySum as  $k => &$value) {
            $thirty = $value['pk_num'] + $thirty;
        }
        $thirtySum = $thirty;
        // 获取今年的注册人数
        $yearSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'today')->select();
        $year = 0;
        foreach ($yearSum as  $k => &$value) {
            $year = $value['pk_num'] + $year;
        }
        $lastSum = $year;
        $array = array();
        $array["thisSum"] = $thisSum;
        $array["sevenSum"] = $sevenSum;
        $array["thirtySum"] = $thirtySum;
        $array["lastSum"] = $lastSum;
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>  $array]));
    }
    public function packagesummaryCount()
    {
        $dateType =trim(input('param.dateType'));
        $tenantId = trim(input('param.tenantId'));
        $startTime = trim(input('param.startTime'));
        $endTime = trim(input('param.endTime'));
        $year =  array();    
        if($dateType=="year"){
        $num = explode('-', $startTime);
        $times=$num[0];
        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-01-01", $times."-02-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[0]['COUNT']=$count1; 
        $year[0]['dateTime']="1";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-02-01", $times."-03-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[1]['COUNT']=$count1; 
        $year[1]['dateTime']="2";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-03-01", $times."-04-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[2]['COUNT']=$count1; 
        $year[2]['dateTime']="3";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-04-01", $times."-05-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[3]['COUNT']=$count1; 
        $year[3]['dateTime']="4";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-05-01", $times."-06-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[4]['COUNT']=$count1; 
        $year[4]['dateTime']="5";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-06-01", $times."-07-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[5]['COUNT']=$count1; 
        $year[5]['dateTime']="6";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-07-01", $times."-08-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[6]['COUNT']=$count1; 
        $year[6]['dateTime']="7";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-08-01", $times."-09-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[7]['COUNT']=$count1; 
        $year[7]['dateTime']="8";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-09-01", $times."-10-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[8]['COUNT']=$count1; 
        $year[8]['dateTime']="9";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-10-01", $times."-11-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[9]['COUNT']=$count1; 
        $year[9]['dateTime']="10";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-11-01", $times."-12-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[10]['COUNT']=$count1; 
        $year[10]['dateTime']="11";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-12-01", $times."-12-31"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['pk_num'] + $one;
        }
        $count1 = $one;
        $year[11]['COUNT']=$count1; 
        $year[11]['dateTime']="12";
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
        }
        
        if($dateType=="month"||$dateType=="week"){
            $num = explode('-', $startTime);
            $years=$num[0];
            $mount=$num[1];
            for($i=1;$i<32;$i++){
                ${'count'.$i} = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereBetweenTime('create_time', $years."-".$mount."-".$i)->limit(1)->order("create_time desc")->find();
                if(${'count'.$i}==""){
                    ${'num'.$i}['COUNT']=0;
                }else{
                    ${'num'.$i}['COUNT']= ${'count'.$i}['pk_num'];
                }
                ${'num'.$i}['dateTime']= $i;
            array_push($year,  ${'num'.$i});
            // array_push($year,  ${'count'.$i});
            }
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
            }
      
    }

    public function profitcountData()
    {
        $tenantId = trim(input('param.tenantId'));
        $thisSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'd')->find();
        if ($thisSum['profit'] == 0) {
            $thisSum = 0;
        }
        // 获取本周的注册人数
        $sevenSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'w')->select();
        $week = 0;
        foreach ($sevenSum as  $k => &$value) {
            $week = $value['profit'] + $week;
        }
        $sevenSum = $week;
        // 获取本月的注册人数
        $thirtySum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'm')->select();
        $thirty = 0;
        foreach ($thirtySum as  $k => &$value) {
            $thirty = $value['profit'] + $thirty;
        }
        $thirtySum = $thirty;
        // 获取今年的注册人数
        $yearSum = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'today')->select();
        $year = 0;
        foreach ($yearSum as  $k => &$value) {
            $year = $value['profit'] + $year;
        }
        $lastSum = $year;
        $array = array();
        $array["thisSum"] = $thisSum;
        $array["sevenSum"] = $sevenSum;
        $array["thirtySum"] = $thirtySum;
        $array["lastSum"] = $lastSum;
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>  $array]));
    }
    public function profitsummaryCount()
    {
        $dateType =trim(input('param.dateType'));
        $tenantId = trim(input('param.tenantId'));
        $startTime = trim(input('param.startTime'));
        $endTime = trim(input('param.endTime'));
        $year =  array();    
        if($dateType=="year"){
        $num = explode('-', $startTime);
        $times=$num[0];
        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-01-01", $times."-02-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[0]['sum']=$count1; 
        $year[0]['dateTime']="1";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-02-01", $times."-03-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[1]['sum']=$count1; 
        $year[1]['dateTime']="2";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-03-01", $times."-04-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[2]['sum']=$count1; 
        $year[2]['dateTime']="3";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-04-01", $times."-05-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[3]['sum']=$count1; 
        $year[3]['dateTime']="4";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-05-01", $times."-06-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[4]['sum']=$count1; 
        $year[4]['dateTime']="5";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-06-01", $times."-07-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[5]['sum']=$count1; 
        $year[5]['dateTime']="6";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-07-01", $times."-08-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[6]['sum']=$count1; 
        $year[6]['dateTime']="7";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-08-01", $times."-09-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[7]['sum']=$count1; 
        $year[7]['dateTime']="8";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-09-01", $times."-10-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[8]['sum']=$count1; 
        $year[8]['dateTime']="9";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-10-01", $times."-11-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[9]['sum']=$count1; 
        $year[9]['dateTime']="10";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-11-01", $times."-12-01"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[10]['sum']=$count1; 
        $year[10]['dateTime']="11";

        $count1 = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereTime('create_time', 'between', [$times."-12-01", $times."-12-31"])->select();
        $one = 0;
        foreach ($count1 as  $k => &$value) {
            $one = $value['profit'] + $one;
        }
        $count1 = $one;
        $year[11]['sum']=$count1; 
        $year[11]['dateTime']="12";
        exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
        }
        
        if($dateType=="month"||$dateType=="week"){
            $num = explode('-', $startTime);
            $years=$num[0];
            $mount=$num[1];
            for($i=1;$i<32;$i++){
                ${'count'.$i} = Db::table('sys_summary')->where(['tenant_id ' => $tenantId])->whereBetweenTime('create_time', $years."-".$mount."-".$i)->limit(1)->order("create_time desc")->find();
                if(${'count'.$i}==""){
                    ${'num'.$i}['sum']=0;
                }else{
                    ${'num'.$i}['sum']= ${'count'.$i}['profit'];
                }
                ${'num'.$i}['dateTime']= $i;
            array_push($year,  ${'num'.$i});
            // array_push($year,  ${'count'.$i});
            }
            exit(json_encode(['code' => 1, 'message' => 'succ', "result" =>$year]));
            }
      
    }
}
